package com.hwh.daoIm;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.hwh.dao.GoodsDao;
import com.hwh.vo.Goods;

import JDBCUtil.UTIL;

public class GoodsDaoImp implements GoodsDao{

public ArrayList<Goods> getGoods(){
		
		ArrayList<Goods> goods = new ArrayList<Goods>();
		PreparedStatement pst = null;
		Connection con = UTIL.getConn();
		
		ResultSet rs = null;
		StringBuffer sql=new StringBuffer("select * from goods");
        try {
            pst = con.prepareStatement(sql.toString());
            //返回一个结果集
            rs = pst.executeQuery();
            while (rs.next()) {
                //商品对象接收结果集的结果
            	Goods gd=new Goods();
                gd.setG_id(rs.getInt("g_id"));
                gd.setG_name(rs.getString("g_name"));
                gd.setG_type(rs.getString("g_type"));
                gd.setG_describe(rs.getString("g_describe"));
                gd.setG_price(rs.getInt("g_price"));
                gd.setSto_id(rs.getInt("sto_id"));
                goods.add(gd);
            }
        } catch (SQLException e) {
            e.printStackTrace();    
        }finally {
        	try {
				UTIL.closeConn(rs, pst, con);
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
        }
		
		return goods;
	}
	
}
